# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n - 2) + fib(n -1)


print(fib(9))
# 快排
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([m for m in qlist[1:] if m <= qb])
        qc = quick([l for l in qlist[1:] if l > qb])
        return qa + [qb] + qc


print(quick([3, 4, 234, 15, 25, 52]))


# 随机插入排序
def insertQuick(qlist):
    for i in range(len(qlist)):
        key = qlist[i]
        j = i - 1
        while j >= 1 and key < qlist[j]:
            qlist[j + 1] = qlist[j]
            j -= 1
            qlist[j + 1] = key
    return qlist
print(insertQuick([3, 4, 234, 15, 25, 52]))




# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i+1):
            print(f'{j}*{i}={i*j} ', end=" ")
        print('\t')


print(n_n())

# 统计字符串中出现次数最多的字符和次数
def contStr():
    str1 = "asdaaaasgjfosdifjiasjdfiaojdio"
    d1 = {}
    for s in str1:
        if s not in d1:
            d1[s] = 1
        else:
            d1[s] += 1

    for k, v in d1.items():
        if v == max(d1.values()):
            print(k, v)


print(contStr())


# Switch语句
def swh():
    d1 = {
        "1":"name",
        "2":"age",
        "3":"adress",
        "4":"sex"
        }
    print(d1["3"])


swh()

# filter()筛选功能
def name(n):
    if n.startswith("刘"):
        return True


print(list(filter(name, ['刘柳', '王刘', '周抗抗'])))

# map()映射方法
def add(i):
    i = i**i + 365
    return i

print(list(map(add, [1, 2, 3, 4, 5])))

# 获取list索引位置
def lindex():
    list1 = [2, 4, 1, 223, 52]
    print(list1.index(1))


lindex()

# 判断字符串中大写的几个，小写的几个
def bs():
    str1 = "IAAAAASJDIOjijdiasdDDDD"
    b = 0
    s = 0
    for i in str1:
        if i.isupper():
            b += 1
        else:
            s += 1
    print(f"大写的：{b}个, 小写的：{s}个")


print(bs())




# 修改元组内部元素不可修改的元素
def tp():
    tp1 = (1, 2, 3, 4, (2, 3, 2, [213, "23", "周抗抗"]))
    tp1[4][3].append("李子")
    print(tp1)


tp()
# 列表推导式
list1 = [l for l in range(10)]
print(list1)


# 集合推导式
sett = {l for l in range(15)}
print(sett)


# 字典推导式
list11 = [1, 2, 3, 4, 5, 6]
d1 = {i:str(list11[i]) for i in range(len(list11))}
print(d1)


# 函数嵌套

# 迭代器
list365 = [1, 2, 3, 4, 5]
L123 = list365.__iter__()
print(L123.__next__())
print(L123.__next__())
print(L123.__next__())
print(L123.__next__())
print(L123.__next__())
# 生成器
def genterion():
    list365 = [1, 2, 3, 4, 5]
    yield list365[3]
    yield list365[0]

a = genterion()
print(a.__next__())
print(a.__next__())




# 装饰器

def wapper(name):
    a = "开启游戏外挂！"
    def inner(*args, **kwargs):
        print(a)
        ret = name(*args, **kwargs)
        print(args, kwargs)
        return ret
    return inner

@wapper
def game(username, password):
    print(f"登录账号密码:{username},{password}")
    return "目标游戏已开始！"

print(game("zkk", password="admin123456"))